<template>
  <a-list :grid="{ gutter: 16, xs: 1, sm: 2, md: 4, lg: 4, xl: 6, xxl: 3 }" :data-source="this.recordsdata">
    <a-list-item slot="renderItem" slot-scope="item, index">
      <a-card :title="'项目名称：'+item.projectName" :description="item.time">
        <h3 style="float: left">开始时间 : {{item.professorWorkBeginTime}}</h3>
        <span>
          <a @click="showModal(item)" style="float: right">紧急请假</a>
          <a-modal
            title="请假原因"
            :visible="visible"
            @ok="postLeave"
            @cancel="handleCancel">
            <!--内容-->
            <a-textarea placeholder="请输入请假原因" :rows="4" v-model = "leaveCause"/>
          </a-modal>
        </span>
      </a-card>
    </a-list-item>
  </a-list>
</template>
<script>
    import '@/assets/less/TableExpand.less'
    import {postAction} from '@/api/manage'
    import {getAction} from "../../api/manage";

    export default {
    data() {
      return {
        leaveCause:"",
        visible:false,
        recordsdata:"",
        itemdata:{},
        url: {
                 list: "/projectProfessorInfo/listByProfessorId",
                delete: "/projectProfessorInfo/delete",
                deleteBatch: "/projectProfessorInfo/deleteBatch",
                exportXlsUrl: "/projectProfessorInfo/exportXls",
                importExcelUrl: "/projectProfessorInfo/importExcel",
                randomChoose: "/projectProfessorInfo/randomChoose",
                queryProfessorNumber: "/projectProfessorInfo/queryProfessorNumber",
                toSendLeaveCause:"/sendLeaveCause",
              },
      };
    },
    mounted(){
      getAction(this.url.list).then((res) => {
        this.recordsdata=res.result.records;
    })
    },
    methods: {
      showModal(item) {
        // 显示请假框
        console.log(item);
        this.visible = true;
        this.itemdata=item;
      },
      handleCancel(){
        this.visible = false;
      },
      postLeave(){
        let params = {
          userId:this.itemdata.dingUserId,
          projectId:this.itemdata.id,
          leaveCause: this.leaveCause,
        }
        // axios发送到后端
        postAction(this.url.toSendLeaveCause,params).then((res)=>{
          if(res.success!=null){
            if (res.success){
              this.$message.success(res.message)
            }else {
              this.$message.error(res.message)
            }
          }
        })
        this.itemdata=null;
        this.leaveCause="";
        this.visible = false;
      }
    }
  };
</script>
<style></style>